﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLogic.BusinessEntity.Entities;
using BusinessLogic.Connectivity.Entities;

namespace BankApplication.BusinessLogic
{
	public class CurrenciesManager
	{
		public static IList<Currency> GetCurrencies(string sessionTicket)
		{

			var serverResponse = ServerProxy.Instance.GetCurrencies();

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}

			return serverResponse.Payload;
		}

		public static IList<CurrencyConversion> GetCurrencyConversions()
		{
			var serverResponse = ServerProxy.Instance.GetCurrencyConversions();

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}

			return serverResponse.Payload.ToList();
		}

		public static void UpdateCurrencyConversion(CurrencyConversion conversion, string sessionTicket)
		{
			var serverResponse = ServerProxy.Instance.UpdateCurrencyConversion(conversion, sessionTicket);

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}
		}

		public static void CreateCurrency(Currency currency, string sessionTicket)
		{
			var serverResponse = ServerProxy.Instance.CreateCurrency(currency, sessionTicket);

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}

		}

		public static void DeleteCurrency(int currencyID, string sessionTicket)
		{
			var serverResponse = ServerProxy.Instance.DeleteCurrency(currencyID, sessionTicket);

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}

		}

		public static void CreateCurrencyConversion(CurrencyConversion conversion, string sessionTicket)
		{
			var serverResponse = ServerProxy.Instance.CreateCurrencyConversion(conversion, sessionTicket);

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}

		}

		public static void DeleteCurrencyConversion(int currencyConversionID, string sessionTicket)
		{
			var serverResponse = ServerProxy.Instance.DeleteCurrencyConversion(currencyConversionID, sessionTicket);

			if (serverResponse.ServerResponseCode != ServerResponseCode.Success)
			{
				throw new ServerException(serverResponse.Details);
			}
		}
	}
}
